<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Admin\Controller as Controller1;
use App\Http\Requests\Api\AdminRequest;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Models\Admin;


class LoginController extends Controller1
{


    //管理员登录
    public function login(Request $request){

        $user_name = $request->username;

        $password = $request->password;
        $user = Admin::where('username',$user_name)->first();
        if(!$user)
            return $this->failed('用户名不存在');

        $token=Auth::guard('admin')->attempt(['username'=>$user_name,'password'=>$password]);

        return $this->failed($token);
        $user->token = $token;

        if($token) {
            $user->token = 'bearer '.$token;;
            return $this->setStatusCode(200)->success($user);
        }
        return $this->failed('密码错误',200);

    }




}
